﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package eu.orangeflash.webapis.wp.mxml {
    import eu.orangeflash.webapis.wp.*;
    import eu.orangeflash.webapis.events.*;
    import mx.managers.*;
    import mx.events.*;
    import mx.rpc.mxml.*;
    import flash.events.*;

    public class Operation extends EventDispatcher implements IMXMLSupport {

        private var sbc:Boolean;// = false
        private var _params:Array;
        private var _methodName:String;
        private var _currentMethod:WPMethod;
        private var _client:WordPress;
        private var _lastResult:Object;

        public function Operation(){
            sbc = false;
            _lastResult = new Object();
            super();
        }
        public function getRecentPosts(numberOfPosts:int):WPMethod{
            return (send(Methods.GET_RECENT_POSTS, [numberOfPosts]));
        }
        private function set _723163380methodName(value:String):void{
            _methodName = value;
        }
        public function send(methodName:String=null, params:Array=null):WPMethod{
            if (methodName != null){
                _methodName = methodName;
            };
            if (params != null){
                _params = params;
            };
            switch (_methodName){
                case Methods.DELETE_POST:
                    invoke(_client.deletePost);
                    break;
                case Methods.EDIT_POST:
                    invoke(_client.editPost);
                    break;
                case Methods.GET_CATEGORY_LIST:
                    invoke(_client.getCategories);
                    break;
                case Methods.GET_POST:
                    invoke(_client.getPost);
                    break;
                case Methods.GET_POST_CATEGORIES:
                    invoke(_client.getPostCategories);
                    break;
                case Methods.GET_RECENT_POST_TITLES:
                    invoke(_client.getRecentPostTitles);
                    break;
                case Methods.GET_RECENT_POSTS:
                    invoke(_client.getRecentPosts);
                    break;
                case Methods.GET_TRACKBACK_PINGS:
                    invoke(_client.getTrackbackPings);
                    break;
                case Methods.NEW_POST:
                    invoke(_client.newPost);
                    break;
            };
            return (_currentMethod);
        }
        private function onWPFault(event:XMLRPCEvent):void{
            dispatchEvent(new XMLRPCEvent(event.type, event.client, event.methodCall));
            CursorManager.removeBusyCursor();
        }
        public function get methodName():String{
            return (_methodName);
        }
        public function getCategories():WPMethod{
            return (send(Methods.GET_CATEGORY_LIST, []));
        }
        public function get params():Array{
            return (_params);
        }
        public function getPost(postID:String):WPMethod{
            return (send(Methods.GET_POST, [postID]));
        }
        public function set showBusyCursor(value:Boolean):void{
            var oldValue:Object;
            oldValue = this.showBusyCursor;
            if (oldValue !== value){
                this._899935860showBusyCursor = value;
                dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, "showBusyCursor", oldValue, value));
            };
        }
        public function get concurrency():String{
            return (null);
        }
        public function getRecentPostTitles(numberOfPosts:int):WPMethod{
            return (send(Methods.GET_RECENT_POST_TITLES, [numberOfPosts]));
        }
        public function set client(value:WordPress):void{
            var oldValue:Object;
            oldValue = this.client;
            if (oldValue !== value){
                this._1357712437client = value;
                dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, "client", oldValue, value));
            };
        }
        public function get showBusyCursor():Boolean{
            return (sbc);
        }
        public function set concurrency(c:String):void{
        }
        public function set methodName(value:String):void{
            var oldValue:Object;
            oldValue = this.methodName;
            if (oldValue !== value){
                this._723163380methodName = value;
                dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, "methodName", oldValue, value));
            };
        }
        public function getTrackbackPings(postID:String):WPMethod{
            return (send(Methods.GET_TRACKBACK_PINGS, [postID]));
        }
        private function onWPResult(event:XMLRPCEvent):void{
            var params:Array;
            params = event.methodCall.response.params;
            _lastResult = ((params.length)==1) ? params[0] : params;
            dispatchEvent(new XMLRPCEvent(event.type, event.client, event.methodCall));
            CursorManager.removeBusyCursor();
        }
        private function set _899935860showBusyCursor(sbc:Boolean):void{
            this.sbc = sbc;
        }
        public function set params(value:Array):void{
            var oldValue:Object;
            oldValue = this.params;
            if (oldValue !== value){
                this._995427962params = value;
                dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, "params", oldValue, value));
            };
        }
        public function get client():WordPress{
            return (_client);
        }
        public function getPostCategories(postID:String):WPMethod{
            return (send(Methods.GET_POST_CATEGORIES, [postID]));
        }
        public function get lastResult():Object{
            return (_lastResult);
        }
        public function initialized(document:Object, id:String):void{
        }
        public function newPost(content:Content, publish:Boolean):WPMethod{
            return (send(Methods.NEW_POST, [content, publish]));
        }
        public function editPost(postID:String, content:Content, publish:Boolean):WPMethod{
            return (send(Methods.EDIT_POST, [postID, content, publish]));
        }
        private function set _1357712437client(value:WordPress):void{
            _client = value;
        }
        public function deletePost(postID:String, publish:Boolean=true):WPMethod{
            return (send(Methods.DELETE_POST, [postID, publish]));
        }
        private function set _995427962params(value:Array):void{
            _params = value;
        }
        private function invoke(method:Function):WPMethod{
            if (_currentMethod != null){
                _currentMethod.removeEventListener(XMLRPCEvent.RESULT, onWPResult);
                _currentMethod.removeEventListener(XMLRPCEvent.FAULT, onWPFault);
            };
            _currentMethod = method.apply(null, _params);
            _currentMethod.addEventListener(XMLRPCEvent.RESULT, onWPResult);
            _currentMethod.addEventListener(XMLRPCEvent.FAULT, onWPFault);
            if (sbc){
                CursorManager.setBusyCursor();
            };
            return (_currentMethod);
        }

    }
}//package eu.orangeflash.webapis.wp.mxml 
